var _MENU={};
Jes.ext({
	Menu : {
		init : function(){
			Jes.query('menu_query_sql@acl',{lo:0},function(da){
				Jes.each(da,function(i){
					if(!_MENU[da[i].pid]) _MENU[da[i].pid]=[];
					_MENU[da[i].pid].push(da[i]);
				});
				var html = '<ul id="menuModel" style="display:none">';
				Jes.each(_MENU[0],function(i){
					html += '<li width="76" jsFunction="Jes.Menu.link(\''+this.url+'\');" id="'+this.id+'"><a href="javascript:void(0);">'+this.mname+'</a>';
					html += Jes.Menu.showChild(this.id,_MENU);
					html += '</li>';
				});
				html += '</ul>';
				Jes('menu_div').innerHTML = html;
				var menuModel = new DHTMLSuite.menuModel();
				DHTMLSuite.configObj.setCssPath('../../lovejes/menu/menu-for-applications/css2/css/');
				menuModel.addItemsFromMarkup('menuModel');
				menuModel.setMainMenuGroupWidth(00);
				menuModel.init();
				var menuBar = new DHTMLSuite.menuBar();
				menuBar.addMenuItems(menuModel);
				menuBar.setTarget('menuDiv');
				menuBar.init();
				showInit(Jes('DHTMLSuite_menuBar_arrow'+_MENU[0][0].id));
			});
		}
		,showChild : function(pid,_MENU){
			var html = '';
			if(_MENU[pid]){
				html += '<ul width="130">';
				Jes.each(_MENU[pid],function(i){
					html += '<li width="76" jsFunction="Jes.Menu.link(\''+this.url+'\');" id="'+this.id+'"><a href="javascript:void(0);">'+this.mname+'</a>';
					html += Jes.Menu.showChild(this.id,_MENU);
					html += '</li>';
				});
				html+= '</ul>';
			}
			return html;
		}
		,link : function(url){
			Jes('main').src=url;
		}
	}
});

function showInit(divObj){
	var objectIndex = divObj.getAttribute('objectRef');
	var obj = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[objectIndex];
	var parentId = divObj.id.replace(/[^0-9]/gi,'');
	var state = obj.menuItem_objects[parentId].getState();
	if(state=='disabled')return;
	obj.menuBarState = !obj.menuBarState;
	if(!obj.menuBarState)obj.hideSubMenus();else{
		obj.hideSubMenus();//obj.__expandGroup(parentId);
	}
}